package test.threads;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Task {
	public static int maxThreadValue = 4;
	
	public static void main(String[] args) {
		Task task = new Task();
	}

	public Task() {
		Runnable print1 = new Print(1);
		Runnable print2 = new Print(2);
		Runnable print3 = new Print(3);
		Runnable print4 = new Print(4);

		Thread thread1 = new Thread(print1);
		Thread thread2 = new Thread(print2);
		Thread thread3 = new Thread(print3);
		Thread thread4 = new Thread(print4);

		thread1.start();
		thread2.start();
		thread3.start();
		thread4.start();
	}

	public class Print implements Runnable {
		private int value;
		private Lock lock = new ReentrantLock();

		public Print(int value) {
			this.value = value;
		}

		public void run(){
			
			lock.lock();
			try{
				for(int i = 0; i<2; i++){
					System.out.println(value);
				}
			} finally {
				lock.unlock();
			}
			
		}
	}
}
